#!/usr/bin/env perl
use warnings;
use strict;

use lib 'lib';

use Test::More tests => 6;
use_ok( 'Guile::Space' );

my @tests = (
    {   title   => 'closures returning values',
        code    => '(+ (foo) (bar) (baz))',
        scope   => { foo => sub { 1 }, bar => sub { 2 }, baz => sub { 3 } },
        result  => 6,
    },
    {   title   => 'closure receiving arguments',
        code    => '(multiply 23 2)',
        scope   => { multiply => sub { $_[0] * $_[1] } },
        result  => 46,
    },
    {   title   => 'closure with arguments returning closure',
        code    => '((make-multiplier 2) 23)',
        scope   => { 'make-multiplier' => sub { my $x = shift; sub { $x * $_[0] } } },
        result  => 46,
    },
    {   title   => 'closure calling closure',
        code    => '(foo bar)',
        scope   => { foo => sub { $_[0]->() * 2 }, bar => sub { 23 } },
        result  => 46,
        skip    => 'TODO',
    },
    {   title   => 'applying a list to a closure',
        code    => '(apply foo (list 1 2 3))',
        scope   => { foo => sub { join '', @_ } },
        result  => '123',
    },
);

my $space = Guile::Space->new;

for my $t (@tests) {

  SKIP: {
        if ( my $msg = $t->{skip} ) { skip $msg . ': ' . $t->{title} => 1 }
        is( $space->run( code => $t->{code}, scope => $t->{scope} ),
            $t->{result},
            $t->{title},
        );
    }
}



